home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / StartupTools / LoadKickC0.lha / LoadKickC0 / src / StartKick.asm < prev   
Assembly Source File  |  1992-01-03  |  4KB  |  211 lines

  1. ;*************************************************************************
  2. ;*                                                                       *
  3. ;* LoadKickC0 V1.1 -- Copyright 1992 by Matthias Scheler                 *
  4. ;*                                                                       *
  5. ;*      This program may be freely copied, as long as all copyright      *
  6. ;*      notices are left intact and unchanged.                           *
  7. ;*                                                                       *
  8. ;*************************************************************************
  9.  
  10.         CSECT text,0
  11.  
  12.         INCLUDE "exec/types.i"
  13.         INCLUDE "exec/execbase.i"
  14.         INCLUDE "exec/resident.i"
  15.  
  16. _AbsExecBase    EQU 4
  17.  
  18. PatchOffset    EQU $7FF00
  19.  
  20.         XREF _SysBase
  21.         XREF _LVODisable
  22.         XREF _LVOSuperState
  23.        
  24.         XREF RelocTab16
  25.  
  26.         XDEF _StartKick
  27. _StartKick:    movem.l 4(sp),a2/a3
  28.  
  29. ; relocate kickstart image
  30.  
  31.         move.l a3,d0        ; calculate offset for relocation
  32.         sub.l #$200000,d0
  33.         lea RelocTab16(pc),a0
  34.         sub.l a1,a1
  35. RelocKickImage:    tst.w (a0)
  36.         beq.s PatchKickImage
  37.         add.w (a0)+,a1
  38.         add.l d0,0(a2,a1.l)
  39.         bra.s RelocKickImage
  40.  
  41. ; patch kickstart memory configuration
  42.  
  43. PatchKickImage:    move.l a3,d0
  44.         swap d0
  45.         addq.l #$08,d0        ; ($C80000 - $C00000) / $10000 = $08
  46.         move.w d0,$2B4(a2)
  47.         move.w d0,$2C8(a2)
  48.  
  49. ; relocate tag for patch
  50.  
  51.         move.l a3,a1
  52.         add.l #PatchOffset,a1
  53.         
  54.         lea ResetTag(pc),a0
  55.         move.l a1,RT_MATCHTAG(a0)
  56.         lea RT_SIZE(a1),a5
  57.         move.l a5,RT_ENDSKIP(a0)
  58.         move.l a5,RT_INIT(a0)
  59.         lea ResetName-ResetTag(a1),a5
  60.         move.l a5,RT_NAME(a0)
  61.  
  62. ; copy patch into kickstart image
  63.  
  64.         move.l a2,a1
  65.         add.l #PatchOffset,a1
  66.         move.w #(ResetEnd-ResetTag)/2-1,d0
  67. PatchResetCode:    move.w (a0)+,(a1)+
  68.         dbf d0,PatchResetCode
  69.  
  70. ; prepare reboot
  71.  
  72.         move.l a2,KickSource
  73.         move.l a3,KickTarget
  74.  
  75.         move.l _SysBase(a4),a6
  76.         lea StartKick(pc),a0
  77.         bsr SetCold
  78.  
  79.         jsr _LVODisable(a6)     ; interrupts off
  80.         jsr _LVOSuperState(a6)    ; call copy code in supervisor mode
  81.  
  82.         bra Reboot
  83.  
  84. ; init and save some exec pointers
  85.  
  86. StartKick:    move.l KickSource(pc),a0
  87.         move.l KickTarget(pc),a1
  88.         lea 2(a1),a2
  89.  
  90.         move.w LIB_NEGSIZE(a6),d2
  91.         movem.l KickMemPtr(a6),d3-d5
  92.  
  93. ; copy kickstart image and recalculate checksum
  94.  
  95.         moveq #8,d0        ; clear old checksum
  96.         swap d0
  97.         clr.l -24(a0,d0.l)
  98.  
  99.         moveq #2,d0        ; 131072 * 4 = 524288
  100.         swap d0
  101.         moveq #0,d1
  102. CopyKickImage:    add.l (a0),d1
  103.         bcc.s NoOverFlow1
  104.         addq.l #1,d1
  105. NoOverFlow1:    move.l (a0)+,(a1)+
  106.         subq.l #1,d0
  107.         bne.s CopyKickImage
  108.  
  109.         not.l d1
  110.         move.l d1,-24(a1)
  111.  
  112. ; create a faked execbase, so that a hard disk driver gets a chance to survive
  113.  
  114.         lea 0(a1,d2.w),a6
  115.         move.l a6,_AbsExecBase.w
  116.  
  117.         move.l #$00220002,SoftVer(a6)
  118.         move.l a6,d0
  119.         not.l d0
  120.         move.l d0,ChkBase(a6)
  121.         clr.l ColdCapture(a6)
  122.         clr.l CoolCapture(a6)
  123.         clr.l WarmCapture(a6)            
  124.  
  125.         lea SoftVer(a6),a0
  126.         moveq #23,d0
  127.         moveq #0,d1
  128. SumLoop1:    add.w (a0)+,d1
  129.         dbf d0,SumLoop1
  130.         not.w d1
  131.         move.w d1,(a0)
  132.  
  133.         movem.l d3-d5,KickMemPtr(a6)
  134.  
  135. ; start OS 2.0 first time
  136.  
  137.         jmp (a2)
  138.  
  139. KickSource:    dc.l 0
  140. KickTarget:    dc.l 0
  141.  
  142. ; reset tag
  143.  
  144. ResetTag:    dc.w RTC_MATCHWORD
  145.         dc.l 0
  146.         dc.l 0
  147.         dc.b RTF_COLDSTART
  148.         dc.b 37
  149.         dc.b 0
  150.         dc.b 109
  151.         dc.l 0
  152.         dc.l 0
  153.         dc.l 0
  154.  
  155. ; set cold capture when OS 2.0 is running
  156.  
  157.         lea RestartKick(pc),a0
  158. SetCold:    move.l a0,ColdCapture(a6)
  159. SumExec:    lea SoftVer(a6),a0
  160.         moveq #23,d0
  161.         moveq #0,d1
  162. SumLoop2:    add.w (a0)+,d1
  163.         dbf d0,SumLoop2
  164.         not.w d1
  165.         move.w d1,(a0)
  166.         rts
  167.  
  168. ; restart kickstart 2.0
  169.  
  170. RestartKick:    lea SoftVer(a6),a0
  171.         moveq #23,d0
  172.         moveq #0,d1
  173. SumLoop3:    add.w (a0)+,d1
  174.         dbf d0,SumLoop3
  175.         not.w d1
  176.         move.w d1,(a0)
  177.  
  178. ; check kickstart
  179.  
  180.         lea ResetTag(pc),a0
  181.         sub.l #PatchOffset,a0
  182.         lea 2(a0),a1
  183.  
  184.         moveq #2,d0        ; 131072 * 4 = 524288
  185.         swap d0
  186.         moveq #0,d1
  187. CheckKickImage:    add.l (a0)+,d1
  188.         bcc.s NoOverFlow3
  189.         addq.l #1,d1
  190. NoOverFlow3:    subq.l #1,d0
  191.         bne.s CheckKickImage
  192.  
  193.         addq.l #1,d1
  194.         bne.s ColdReboot    ; kickstart is corrupt
  195.  
  196.         jmp (a1)        ; jump into OS 2.0
  197.  
  198. ; reboot
  199.  
  200. ColdReboot:    clr.l ChkBase(a6)    ; force complete reset
  201. Reboot:        lea $01000000,a0    ; entry point for rom kickstart
  202.         sub.l -20(a0),a0
  203.         move.l 4(a0),a0
  204.         jmp -2(a0)        ; jump on reset instruction
  205.  
  206. ResetName:    dc.b "LoadKickC0",0
  207.         ds.w 0
  208.  
  209. ResetEnd:
  210.         END
  211.